//
// Created by zheng on 2024/11/15.
//

#pragma once

#include <stdint.h>

template<typename T>
struct BasicWrapper {
    T *m_data;
    bool ref = false;

    BasicWrapper() {
        m_data = new T();
    }

    BasicWrapper(T *ref) {
        m_data = ref;
    }

    ~BasicWrapper() {
        if (ref) {
            return;
        }
        delete m_data;
    }

    void setValue(T data) {
        *m_data = data;
    }

    void setPtr(T *data) {
        m_data = data;
    }

    T *getPtr() {
        return m_data;
    }

    T getValue() {
        return *m_data;
    }
};


template<typename T>
struct BasicArrayWrapper {
    T *m_data;
    size_t m_len;
    bool ref = false;

    BasicArrayWrapper(size_t len) {
        m_data = new T(len);
        m_len = len;
    }

    BasicArrayWrapper(T *other, size_t len) {
        m_data = other;
        m_len = len;
        ref = true;
    }

    ~BasicArrayWrapper() {
        if (ref) {
            return;
        }
        delete m_data;
    }

    T *get() {
        return m_data;
    }

    void set(size_t index, T value) {
        m_data[index] = value;
    }

    T getValue(size_t index) {
        return m_data[index];
    }

    size_t size() {
        return m_len;
    }
};